/*
 * MessagesRead.java
 *
 * Created on November 15, 2008, 12:48 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package jollylengkono.skripsi.Messages.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import jollylengkono.skripsi.dao.MessagesDao;
import jollylengkono.skripsi.model.Messages;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

/**
 *
 * @author JollkY
 */
public class MessagesRead extends Action {
    private String FORWARD;
    
    /** Creates a new instance of MessagesRead */
    public MessagesRead() {
    }
    
    public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response) {
        long id = Long.parseLong(request.getParameter("msg_id"));
        Messages msg = (Messages) new MessagesDao().read(id);
        if (msg==null) {
            this.FORWARD = "fail";
        } else {
            this.FORWARD = "success";
            request.setAttribute("message", msg);
        }
        return mapping.findForward(FORWARD);
    }
    
}
